import Toast from '@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sign: null,
    ispopupShow: false,
    ispopupShows: false,
    ids: null,
    radio: '1',
    oldradio: '1',
    GlStateOneValue: '',
    GlStateOneIndex: 0,
    GlStateTwoValue: '',
    GlStateTwoIndex: 0,
    StepperValue: 1,
    currentValue: 50,
    weuiValue: '',
    customStyleSelect: "padding:0 0 0 20rpx;height: 100%;width:100%;color:#808285;",
    columnsGlStateOne: [{
      id: 0,
      text: '选择功率'
    }, {
      id: 1,
      text: '1~100'
    }, {
      id: 2,
      text: '101~200'
    }],
    columnsGlStateTwo: [{
      id: 0,
      text: '选择功率'
    }, {
      id: 1,
      text: '1~100'
    }, {
      id: 2,
      text: '101~200'
    }, {
      id: 3,
      text: '201~300'
    }],
  },

  onRadioChange(event) {
    this.setData({
      radio: event.detail,
    });
  },
  onConfirmPattern() {
    let that = this
    that.setData({
      ispopupShows: false,
      oldradio: that.data.radio
    })
    console.log(that.data.radio);
  },
  onClose() {
    let that = this
    that.setData({
      ispopupShows: false,
      radio: that.data.oldradio
    })
  },
  patterncut(e) {
    console.log('运行模式');
    let that = this
    that.setData({
      ispopupShows: true,
      radio: e.currentTarget.dataset.index
    })
  },
  onDrag(event) {
    let that = this
    that.setData({
      currentValue: event.detail.value,
    });
  },
  onStepper(event) {
    let that = this
    that.setData({
      StepperValue: event.detail
    })
    console.log(event.detail);
  },
  onClickInput(e) {
    let that = this
    that.setData({
      sign: e.currentTarget.dataset.sign,
      ispopupShow: true
    })
  },
  cancelpicker(e) {
    let that = this
    that.setData({
      ispopupShow: false
    })
    setTimeout(() => {
      that.setData({
        sign: null
      })
    }, 200)
  },
  onConfirmGlStateOne(event) {
    let that = this
    that.setData({
      GlStateOneIndex: event.detail.index,
      GlStateOneValue: event.detail.value.id == 0 ? '' : event.detail.value.text,
      ispopupShow: false
    })
  },
  onConfirmGlStateTwo(event) {
    let that = this
    that.setData({
      GlStateTwoIndex: event.detail.index,
      GlStateTwoValue: event.detail.value.id == 0 ? '' : event.detail.value.text,
      ispopupShow: false
    })
  },
  bindHideKeyboard(e) {
    let that = this
    that.setData({
      weuiValue: e.detail.value
    })
  },
  submit() {
    let that = this
    let params = {}
    params.currentValue = that.data.currentValue
    params.StepperValue = that.data.StepperValue
    params.GlStateOneIndex = that.data.GlStateOneIndex
    params.GlStateTwoIndex = that.data.GlStateTwoIndex
    params.weuiValue = that.data.weuiValue
    params.oldradio = that.data.oldradio
    console.log(params);
    const toast = Toast.loading({
      duration: 0, // 持续展示 toast
      forbidClick: true,
      message: '加载中...',
      selector: '#custom-selector',
      onClose: () => {
        wx.navigateBack({
          data: 1
        })
      },
    });
    let second = 3;
    const timer = setInterval(() => {
      second--;
      if (second) {
        toast.setData({
          message: `${second}%`,
        });
      } else {
        clearInterval(timer);
        toast.setData({
          type: 'success',
          message: `完成`,
        });
        setTimeout(() => {
          Toast.clear();
        }, 1000)
      }
    }, 1000);


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    that.setData({
      ids: JSON.parse(options.ids)
    })
    console.log(JSON.parse(options.ids));
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})